import request from '@/utils/request'

export function getArticleCategoryList(params: ArticleCategoryListParamsType) {
  return request({
    url: '/cms/category',
    method: 'get',
    params,
  })
}

export function submitArticleCategory(data: any) {
  return request({
    url: data.id ? `/cms/category/${data.id}.html` : `/cms/category.html`,
    method: data.id ? 'put' : 'post',
    data,
  })
}

export function setArticleCategoryStatus(id: number, status: number) {
  return request({
    url: `/cms/category/set_status/${id}/${status}`,
    method: 'put',
  })
}

export function deleteArticleCategory(id: number) {
  return request({
    url: `/cms/category/${id}`,
    method: 'delete',
  })
}

export function getArticleList(params: ArticleListParamsType) {
  return request({
    url: '/cms/cms',
    method: 'get',
    params,
  })
}

export function getArticleInfo(id: number) {
  return request({
    url: `/cms/cms/${id}`,
    method: 'get',
  })
}

export function submitArticle(data: any) {
  return request({
    url: '/cms/cms',
    method: 'post',
    data,
  })
}

export function delArticle(id: number) {
  return request({
    url: `/cms/cms/${id}`,
    method: 'delete',
  })
}

export function bindProduct(id: number, data: { product_id: number }) {
  return request({
    url: `cms/cms/relation/${id}`,
    method: 'put',
    data,
  })
}

export function unbindProduct(id: number) {
  return request({
    url: `cms/cms/unrelation/${id}`,
    method: 'put',
  })
}
